#!/bin/sh

TAG=$1
ENDE=0
SUCCESS=0
DIFF=0
RUN=0

LOGDIR=/data/rate_test

if [ ! -d $LOGDIR ]
then
	echo $LOGDIR does not exist
  echo -n "mkdir -p $LOGDIR..."
  mkdir -p $LOGDIR
	echo "ok"
fi

while [ $ENDE -eq 0 ]
do
	echo RUN: $RUN
	./test_rate >$LOGDIR/run$RUN$TAG.log
	r=$?

	RUN=$[ RUN +1 ]

	case $r in
			0)
					SUCCESS=$[ $SUCCESS + 1 ]
					;;
			1)
					ENDE=1
					;;
			2)
					ENDE=1
					;;
			3)  DIFF=$[ $DIFF + 1 ]
					;;
			*)
			echo unknown return code $r!
			exit 1
			;;
			
	esac

	sleep 1
done

echo $RUN total runs
echo $SUCCESS successful runs
echo $DIFF runs with differences between timecounter and counter